package com.twu.biblioteca.Library1;

import java.io.*;

public class Mainclass extends Library
{
      static Library Lib;
     public static String uname,password;
    static int get_choice()                        throws IOException
   {
       DataInputStream get_input= new DataInputStream(System.in);
       System.out.println("****WELCOME TO BANGALORE PUBLIC LIBRARY****");         //To get the choice from the user
       System.out.println("Select an option");
       System.out.println("1.View Books in the Book");
       System.out.println("2.Reserve a Book");
       System.out.println("3.View Membership Details");
       System.out.println("4.View the list of Movies");
       String s1=get_input.readLine();
       return (Integer.parseInt(s1));

   }

    public static boolean login_user( boolean chk_loggedin)               throws IOException
    {

        DataInputStream get_input= new DataInputStream(System.in);
        if(!chk_loggedin)
        {   Lib=new Library();
            System.out.println("UNAME:");
            uname=get_input.readLine();
            System.out.println("PASSWORD:");
            password=get_input.readLine();
            chk_loggedin=Lib.Authenticate_user(uname,password);
        }
       return chk_loggedin;

    }

    static int get_bookid()              throws IOException
    {
        DataInputStream get_input= new DataInputStream(System.in);
        System.out.println("Enter Book ID");
        String s2=get_input.readLine();
        return (Integer.parseInt(s2));

    }

    public static void main(String arg[])  throws IOException
    {
        DataInputStream get_input= new DataInputStream(System.in);
        int choice;
        int option;
        Lib=new Library();
        Boolean flag=false;
        Boolean chk_loggedin=false;

        do
        {   choice=get_choice();
            switch(choice)
            {
                case 1:
                    Lib.view_books();                            //Fn Call To view books in the library
                    break;
                case 2:
                    chk_loggedin=login_user(chk_loggedin);
                    if(chk_loggedin)
                    {

                        int bid=get_bookid();
                        flag=Lib.is_bookavailable(bid);       //Fn call to check if the particular book is available
                        if(flag)
                        {
                        System.out.println("Book reserved");
                        }
                        else
                        {
                        System.out.println("Sorry book not available");
                        }
                    }
                    else
                    {
                        System.out.println("Sorry You are not a Member...Please Register");
                    }

                    break;
                case 3:
                    if(chk_loggedin)
                    {
                        Lib .view_details(uname);                      //Fn call to view the membership details
                    }
                    else
                    {
                        System.out.println("Please talk to Librarian...Thank You");
                    }

                    break;

                case 4:
                    Lib.view_movies();
                    break;
                default:
                       System.out.println("Enter valid option");
            }

            System.out.println("Enter 1 to continue");
            String s3=get_input.readLine();
            option=Integer.parseInt(s3);
        }while(option==1);



    }
}

